<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
  <style>
    .ni {
      /* margin-top: 10px; */
      background: red;
      padding-top: 10px;
    }

    div {
      width: 100px;
      height: 100px;
      background-color: aqua;
    }

    #aaa {
      width: 100px;
      height: 100px;
      background-color: pink;
    }
  </style>
</head>

<body>
  <span class="">1</span>
  <span class="youhua">1</span>
  <input type="text" />
  <div id="some-element-you-want-to-animate"></div>
  <div id="aaa"></div>
  <script>
    let input = document.querySelector("input");
    let flag = false;
    function handlerCallback(fn) {
      return function () {
        if (!flag) {
          flag = true;
          requestAnimationFrame(fn.bind(this, arguments[0]));
        }
      };
    }

    const element = document.getElementById(
      "some-element-you-want-to-animate"
    );
    let start, previousTimeStamp;
    let done = false;

    function step(timestamp) {
      if (start === undefined) {
        start = timestamp;
      }
      const elapsed = timestamp - start;
      if (previousTimeStamp !== timestamp) {
        // 这里使用 `Math.min()` 确保元素刚好停在 400px 的位置。
        const count = Math.min(0.1 * elapsed, 4000);
        element.style.transform = "translateX(" + count + "px)";
        if (count === 4000) done = true;
      }

      if (elapsed < 4000) {
        // 在两秒后停止动画
        previousTimeStamp = timestamp;
        if (!done) {
          window.requestAnimationFrame(step);
        }
      }
    }
    window.requestAnimationFrame(step);
  </script>
</body>

</html>